<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

	<h:head></h:head>
 <body>
 <ui:composition template="/Template/TemplateAdmin.xhtml">
 			<ui:define name="AdminContent">
 			<h:form id="form">

				<f:facet name="header">Employee</f:facet>
				<p:panelGrid>
				<p:row>
						<p:column>
							<p:outputLabel value="#{editEmployeeView.employee.getClass().getSimpleName()}" />
						</p:column>
				</p:row>
					<p:row>
						<p:column>
							<p:outputLabel value="Code" />
						</p:column>
						<p:column>
							<p:inputText id="code"
								value="#{editEmployeeView.employee.codfisc}" required="true" />
						</p:column>
						<p:column>
							<p:message for="code" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<p:outputLabel value="Name" />
						</p:column>
						<p:column>
							<p:inputText id="name" value="#{editEmployeeView.employee.name}"
								required="true" />
						</p:column>
						<p:column>
							<p:message for="name" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<p:outputLabel value="Surname" />
						</p:column>
						<p:column>
							<p:inputText id="surname"
								value="#{editEmployeeView.employee.surname}" required="true" />
						</p:column>
						<p:column>
							<p:message for="surname" />
						</p:column>
					</p:row>
					
					<p:row>
						<p:column>
							<p:outputLabel value="Username" />
						</p:column>
						<p:column>
							<p:inputText id="username"
								value="#{editEmployeeView.employee.username}" required="true">
								<f:validateLength minimum="5" maximum="10" />
							</p:inputText>
						</p:column>
						<p:column>
							<p:message for="username" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<p:outputLabel value="Password" />
						</p:column>
						<p:column>
							<p:inputText id="password" value="#{editEmployeeView.employee.password}" ><f:validateLength minimum="5" maximum="10" /></p:inputText>
						</p:column>
						<p:column>
							<p:message for="password" />
						</p:column>
					</p:row>
				<ui:fragment rendered="#{editEmployeeView.employee.payMethod!=null}">
				<p:row>
							<p:column>
								<p:outputLabel value="PayMethod" /><br />
								<p:outputLabel value="#{editEmployeeView.employee.payMethod.getClass().getSimpleName()}"></p:outputLabel>
							</p:column>
							<p:column>
								<p:commandButton value="DeletePayMethod" action="#{editEmployeeView.deletePaymethod()}"></p:commandButton>
							</p:column>
							</p:row>
							</ui:fragment>
				<ui:fragment rendered="#{editEmployeeView.employee.payMethod==null}">
				<p:row>
					<p:column>
					<p:outputLabel value="Type of Paymethod" /></p:column>
					<p:column><p:selectOneMenu value="#{editEmployeeView.visibFragment}"
						onchange="#{editEmployeeView.instancePayMethod()}">
						<f:selectItem itemLabel="Cash on office" itemValue="" />
						<f:selectItem itemLabel="Bank" itemValue="BankPayMethod" />
						<f:selectItem itemLabel="SendMail" itemValue="SendMailPayMethod" />
						 <f:ajax render="@form"/>
					</p:selectOneMenu>
					</p:column>
				</p:row>
				</ui:fragment>
				<ui:fragment id="BankPayMethod"
						rendered="#{editEmployeeView.method.getClass().getSimpleName() eq  'BankPayMethod'}">
						<p:row>
							<p:column>
								<p:outputLabel value="Iban" />
							</p:column>
							<p:column>
								<p:inputText id="iban" value="#{editEmployeeView.iban}" ></p:inputText>
							</p:column>
							<p:column>
								<p:message for="iban"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>
					<ui:fragment id="SendMailPayMethod"
						rendered="#{editEmployeeView.method.getClass().getSimpleName() eq  'SendMailPayMethod'}">
						<p:row>
							<p:column>
								<p:outputLabel value="address" />
							</p:column>
							 <p:column>
								<p:inputText id="address" value="#{editEmployeeView.address}" ></p:inputText>
							</p:column>
							<p:column>
								<p:message for="address"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>
			
				
				<ui:fragment rendered="#{editEmployeeView.association!=null}">
				<p:row>
							<p:column>
								<p:outputLabel value="Association" />
							</p:column>
						<p:column><p:commandButton value="DeleteAssociation" action="#{editEmployeeView.DeleteAssociation()}"></p:commandButton>
							</p:column>
							</p:row>
				</ui:fragment>
				<ui:fragment rendered="#{editEmployeeView.association==null}">
				<p:row>
							<p:column>
								<p:outputLabel value="Association" />
							</p:column>
						<p:column><p:commandButton value="Add Union Association"  update="@form" action="#{editEmployeeView.AddAssociation()}"></p:commandButton>
							</p:column>
							</p:row>
				</ui:fragment>
							
							
							
						
				<ui:fragment id="association"
						rendered="#{editEmployeeView.association.getClass().getSimpleName() eq  'Union'}">
						<p:row>
							<p:column>
								<p:outputLabel value="Union tax" />
							</p:column>
							<p:column>
								<p:inputText id="tax" value="#{editEmployeeView.union_tax}"  ><f:validateDoubleRange minimum="0"></f:validateDoubleRange></p:inputText>
							</p:column>
							
							<p:column>
								<p:message for="tax"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>
		 		<ui:fragment
						rendered="#{editEmployeeView.employee.getClass().getSimpleName() eq 'Salaried' ||editEmployeeView.employee.getClass().getSimpleName() eq 'Commissioned'}">
						<p:row>
							<p:column>
								<p:outputLabel value="Monthly salary" />
							</p:column>
							<p:column>
								<p:inputText id="salary" binding="#{salary}" value="#{editEmployeeView.monthly_salary}" ><f:validateDoubleRange minimum="0"></f:validateDoubleRange></p:inputText>
							</p:column>
							<p:column>
								<p:message for="salary"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>
					<ui:fragment
						rendered="#{editEmployeeView.employee.getClass().getSimpleName() eq 'Commissioned'}">
						<p:row>
							<p:column>
								<p:outputLabel value="Sales percent" />
							</p:column>
							<p:column>
								<p:inputText id="percent" binding="#{sales}" value="#{editEmployeeView.sales_percent}" ><f:validateDoubleRange minimum="0"></f:validateDoubleRange></p:inputText>
							</p:column>
							<p:column>
								<p:message for="percent"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>

					<ui:fragment
						rendered="#{editEmployeeView.employee.getClass().getSimpleName() eq 'Contractor' }">
						<p:row>
							<p:column>
								<p:outputLabel value="Hourly rate" />
							</p:column>
							<p:column>
								<p:inputText id="rate"  value="#{editEmployeeView.hourlyRate}" ><f:validateDoubleRange minimum="0"></f:validateDoubleRange></p:inputText>
							</p:column>
							<p:column>
								<p:message for="rate"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>


					<p:row>
						<p:column colspan="2">
							<p:dialog header="Update employee" widgetVar="dialogYes"
								minHeight="40">
								<p:panelGrid columns="1">
									<h:outputText value="Dati Modificati" />
									<p:button value="Ok" outcome="employeeList"></p:button>
								</p:panelGrid>
							</p:dialog>
							<p:dialog header="Update Employee" widgetVar="dialogNo"
								minHeight="40">
								<p:panelGrid columns="1">
									<h:outputText value="#{editEmployeeView.message}" />
								</p:panelGrid>
							</p:dialog>
							<p:commandButton action="#{editEmployeeView.updateEmployee()}"
								value="UpdateEmployee Employee" update="form" />
						</p:column>
					</p:row>
				</p:panelGrid>
				</h:form>
</ui:define>
</ui:composition>
 </body>
 </html>